package manage.action;

import m.common.action.ActionMeta;
import m.common.action.RequestMeta;
import m.common.model.util.QueryPage;
import m.system.util.JSONMessage;
import manage.model.IconInfo;
import manage.service.IconInfoService;

import java.io.File;
import java.util.Map;

@ActionMeta(name="manage/iconInfo")
public class IconInfoAction extends ManageAction {

	/**
	 * 上传文件
	 * 
	 */
	public JSONMessage upload(){
		JSONMessage message=new JSONMessage();
		try {
			verifyAdminOperPower("manage_system_power");
			Map<String,File> map=super.getFileMap();
			IconInfo model=null;
			for(String key : map.keySet()){
				String name=map.get(key).getName();
				model=new IconInfo();
				model.setName(name.substring(name.indexOf("_uploadFile_")+12));
				getService(IconInfoService.class).saveIcon(model,map.get(key));
				break;
			}
			message.push("model", model);
			fillJSONResult(message,true,"");
		} catch (Exception e) {
			fillJSONResult(message,false,e);
		}
		return message;
	}

	/**
	 * 获取icon列表
	 * 
	 */
	@RequestMeta(params= {"page","name"})
	public JSONMessage iconList(QueryPage page,String name){
		JSONMessage message=new JSONMessage();
		try{
			//verifyAdminOperPower("manage_system_power");
			message.push("list", getService(IconInfoService.class).getIconList(page,name));
			fillJSONResult(message,true,"");
		}catch(Exception e){
			fillJSONResult(message,false,e);
		}
		return message;
	}

}
